#用户数据
studentInfos = {
    "xiaowang":{"user":"xiaowang","password":"123","money":1000},
    "xiaohong":{"user":"xiaohong","password":"456","money":800},
    "xiaohuang":{"user":"xiaohuang","password":"789","money":100},
    "xiaozhang":{"user":"xiaozhang","password":"666","money":666}
}
current_users = ""
#交互界面
def show_jiemian():
    print("-"*20,"界面","-"*20)
    print(" "*3,"{:<10}{:<10}".format("1.登陆","2.查询余额"))
    print(" "*3,"{:<10}{:<10}".format("3.存钱","4.取钱"))
    print(" "*3,"{:<10}".format("5.注销"))
    print("-"*46)

def login():
    username = input("请输入用户名：")
    password = input("请输入密码：")
    global current_users
    global studentInfos
    if username not in studentInfos:
        print("输入的用户名不存在")
        return
    if studentInfos[username]["password"] == password:
        current_users = username
        print('{:<46}'.format("登陆成功，欢迎你" + current_users))
        return
    else:
        print('{:<46}'.format("输入的密码错误，请重新输入"))
        login()
        return

def loginout():
    global current_users
    current_users = ""
    print("=" * 77)
    print("see you next time")
    print("=" * 77)

def checkbanlance():
    global current_users
    global studentInfos
    print("=" * 77)
    print(current_users + "你的账户余额为：{}".format(studentInfos[current_users]["money"]))
    print("=" * 77)

def savemoney():
    global current_users
    global studentInfos
    try:
        money = float(input("请输入存钱金额："))
    except:
        print("=" * 30, "请输入一个数值")
        savemoney()
        return

    if money <= 0:
        print("=" * 30, "请输入一个大于零的数值")
        savemoney()
        return
    studentInfos[current_users]["money"]+=money
    print("=" * 77)
    print("操作成功，你的账户余额为：{}".format(studentInfos[current_users]["money"]))
    print("=" * 77)

def getmoney():
    global current_users
    global studentInfos
    try:
        money = float(input("请输入取钱金额："))
    except:
        print("=" * 30, "请输入一个数值")
        savemoney()
        return
    if money <= 0:
        print("请输入一个大于零的数值")
        savemoney()
        return
    if money > studentInfos[current_users]["money"]:
        print("余额不足，请重新输入取钱金额")
        getmoney()
        return
    else:
        studentInfos[current_users]["money"]-=money
        print("=" * 77)
        print("操作成功，你的账户余额为：{}".format(studentInfos[current_users]["money"]))
        print("=" * 77)

def gohead():
    global current_users
    while True:
        show_jiemian()
        operatekey = input("请输入操作代码")
        if operatekey == "1":
            login()
        elif operatekey in ["2","3","4","5"]:
            if current_users == "":
                print("请先登陆系统")
                continue
            if operatekey == "2":
                checkbanlance()
            elif operatekey == "3":
                savemoney()
            elif operatekey == "4":
                getmoney()
            elif operatekey == "5":
                loginout()
        else:
            print("输入有误，请重新输入！！！")

gohead()

#print(studentInfos["xiaowang"]["money"])




